package com.masterviame.Authc.service.Impl;

import com.masterviame.Authc.pojo.Permission;
import com.masterviame.Authc.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by mastervictory on 2017/12/14.
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,
isolation = Isolation.DEFAULT,timeout = 20)
public class PermissionServiceImpl implements PermissionService{

    @Autowired
    private PermissionService permissionService;

    @Override
    public void createPermisssion(Permission permission) {
        if (permission!=null)
            permissionService.createPermisssion(permission);
        throw new NullPointerException("get permission is null");
    }

    @Override
    public void stopPermission(long permissionid) throws Exception {
        Permission permission=permissionService.getPermissionByid(permissionid);
        if (permission!=null)
            throw new Exception("permission is not exist,stop is not success");
        permission.setAvailable(false);
        permissionService.updatePermission(permission);
    }

    @Override
    public void deletePermissions(long permissionid) {
        permissionService.deletePermissions(permissionid);
    }

    @Override
    public List<Permission> getPermissions() {
        List<Permission> permissionList=permissionService.getPermissions();
        return permissionList;
    }

    @Override
    public Permission getPermissionByid(long permission) {
        Permission permissions=permissionService.getPermissionByid(permission);
        return permissions;
    }

    @Override
    public void updatePermission(Permission permission) {
        permissionService.updatePermission(permission);
    }
}
